layui.use(['table','form','element'], function(){
    var table = layui.table;
    var form = layui.form;
    var element = layui.element;
    var layer = layui.layer;
    var $ = layui.$;

    loadResources();

    function loadResources() {
        $.ajax({
            url: serverUrl + '/index/getResources',
            type:'get',
            dataType:'json',
            success:function (result) {
                console.log(result);
                var $nav = $("ul.layui-nav-tree");
                $.each(result.data,function (i,parent) {
                    if( parent.pid == 0 ) {
                        var li = '<li class="layui-nav-item">'
                            + '<a class="" href="javascript:;">'+parent.title+'</a>'
                            + '<dl class="layui-nav-child">';
                        $.each(result.data, function (j, child) {
                            if(child.pid == parent.id && child.type == 0) {
                                li += '<dd><a href="' + webUrl + child.url+'.html">'+child.title+'</a></dd>'
                            }
                        })
                        li += '</dl>'
                        li += '</li>';
                        $nav.append(li);
                    }
                });
                // form.render("nav-left");
                var layFilter = $nav.attr('lay-filter');
                element.render('nav', layFilter);
            },
            error:function (xhr) {
                layer.msg('出错了');
            }
        })
    }
});
